//
//  NSDate+Extension.m
//  百思不得姐
//
//  Created by qianfeng on 16/3/3.
//  Copyright © 2016年 高炜. All rights reserved.
//

#import "NSDate+Extension.h"

@implementation NSDate (Extension)
-(NSDateComponents *)componentsFromDtae:(NSDate *)date
{
    NSCalendar *calender =[NSCalendar currentCalendar];
    return [calender components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond fromDate:date toDate:self options:0];
}
-(BOOL)isThisYear
{
    NSCalendar *calender =[NSCalendar currentCalendar];
    NSInteger nowYear =[calender component:NSCalendarUnitYear fromDate:[NSDate date]];
    NSInteger selectedYear =[calender component:NSCalendarUnitYear fromDate:[NSDate date]];
    return nowYear==selectedYear;
}
-(BOOL)isToday
{
    NSDateFormatter *fm =[[NSDateFormatter alloc]init];
    fm.dateFormat =@"yyyy-MM-dd";
    NSString *nowDate =[fm stringFromDate:[NSDate date]];
    NSString *selectedDate =[fm stringFromDate:self];
    return [nowDate isEqualToString:selectedDate];
}
-(BOOL)isYesterday
{
    NSDateFormatter *fm =[[NSDateFormatter alloc]init];
    fm.dateFormat =@"yyyy-MM-dd";
    NSDate *nowDate =[fm dateFromString:[fm stringFromDate:[NSDate date]]];
    NSDate *selectedDate =[fm dateFromString:[fm stringFromDate:self]];
    NSCalendar *calendar =[NSCalendar currentCalendar];
    NSDateComponents *compon =[calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:selectedDate toDate:nowDate options:0];
    return compon.year==0&&compon.month==0&&compon.day==1;
}
@end
